home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cgraph / cgraph1.c < prev   
Text File  |  1986-02-17  |  26KB  |  756 lines

  1. /***************************** C _ G R A P H . C ************************/
  2. /*  ....Fast dot and line functions for IBM's EGA adapter in hires      */
  3. /*    (640x350) color mode                                              */
  4. /*    Also double buffering for 256k ega's!!!                           */
  5. /*  This version uses the DeSmet (ver 2.4) C compiler with its built    */      
  6. /* in inline assembler.                                                 */
  7. /*                                                                      */
  8. /* (c)Copywrite 1985 E. Lear - use only for non commercial programming  */
  9. /************************************************************************/
  10.  
  11. /* Define the interrupt for ega's bios calls */
  12. #define     VIDEO_INT        0x0010
  13.  
  14. /* Defines for the various modes available from ega's bios              */
  15. /* For more information refer to the Options and Adapters reference     */
  16. /* manual.                                                              */
  17. #define     SET_MODE         0x0000
  18. #define     SET_CUR_TYPE     0x0100
  19. #define     SET_CUR_POS      0x0200
  20. #define     READ_CUR_POS     0x0300
  21. #define     READ_PEN_POS     0x0400
  22. #define     SELECT_PAGE      0x0500
  23. #define     SCROLL_UP        0x0600
  24. #define     SCROLL_DOWN      0x0700
  25. #define     READ_ATC         0x0800
  26. #define     WRITE_ATC        0x0900
  27. #define     WRITE_ATCO       0x0A00
  28. #define     SET_PAL          0x0B00
  29. #define     WRITE_DOT        0x0C00
  30. #define     READ_DOT         0x0D00
  31. #define     WRITE_TTY        0x0E00
  32. #define     READ_MODE        0x0F00
  33. #define     SET_PAL_REG      0x1000
  34. #define     CHAR_GEN         0x1100
  35. #define     SELECT_ALT       0x1200
  36. #define     WRITE_STR        0x1300
  37.  
  38.  
  39. unsigned x,y;
  40.  
  41. /*  Use these values with _doint() for calling IBM's functions and
  42.     interrupts */
  43.  
  44. extern unsigned _rax, _rbx, _rcx, _rdx, _rsi, _rdi, _res, _rds;
  45. extern void _doint();
  46.  
  47. /*********************** S E T _ V I D E O _ M O D E **********************/
  48. /* 
  49.          function set_video_mode(mode):
  50.  
  51.               Inputs:  int - (0..16) = ( mode )
  52.  
  53.               Returns:  none.
  54.  
  55.               Example:  set_video_mode(0x10) (Set up 640x350 hi-res mode) 
  56. */ 
  57.  
  58.  
  59. void set_video_mode(mode)
  60.    unsigned mode;
  61.    {
  62.     _rax = SET_MODE | mode;
  63.     _doint(VIDEO_INT);
  64.    }
  65.  
  66.  
  67. /*********************** S E T _ P A L _ R E G ************************/
  68. /*
  69.         function set_pal_reg(pal_reg,pal_val)
  70.       
  71.               Inputs: int - (0..15) = ( pal_reg )
  72.                       int - (0..63) = ( pal_val ) 
  73.  
  74.               Returns: none 
  75.  
  76.               Example: set_pal_reg(0,1) - (set normally black background
  77.                                            to blue.)
  78.   
  79. */
  80. void set_pal_reg(pal_reg, pal_val)
  81.    unsigned pal_reg, pal_val;
  82.    {
  83.     _rax = SET_PAL_REG;
  84.     _rbx = (pal_val << 8) | (pal_reg && 0x00ff);
  85.     _doint(VIDEO_INT);
  86.    }
  87.  
  88. /*********************** B _ W R I T E _ D O T ************************/
  89. /* 
  90.         function b_write_dot(page,row,col,color)
  91.  
  92.               Inputs: int - (0..1) = ( page )  (In hires mode. i.e 640x350)
  93.                       int - (0..349) = ( row )    "        "        "
  94.                       int - (0..639) = ( col )    "        "        "
  95.                       int - (0..15)  = ( color ) ( In 16 color modes )
  96.  
  97.               Returns: none.
  98.  
  99.               Example: b_write_dot(0,20,20,1) - Write a blue dot on page 
  100.                                                 one at location 20,20.
  101. */      
  102.  
  103. void b_write_dot(page,row,col,color)
  104.    unsigned page,row,col,color;
  105.    {
  106.     _rax = WRITE_DOT | color;
  107.     _rbx = page << 8;
  108.     _rdx = row;
  109.     _rcx = col;
  110.     _doint(VIDEO_INT);
  111.    }
  112.  
  113. /*  pixel table for the write dot routines ! */
  114. int pixel_table[8] = { 0x4080, 0x1020, 0x0408, 0x0102 };
  115.  
  116.  
  117. /**************************** W R I T E _ D O T **********************/
  118. /* this is the 'fastest' version of write_dot (no color but white)   */
  119. /* This is the ultra fast write one color write dot routine          */
  120. /* s/r must be off and all planes must be enabled (white)            */
  121.  
  122. void write_dot(x,y)
  123.     unsigned x,y;
  124. {
  125. #asm
  126. public write_dot
  127. write_dot:
  128.       mov   ax,[bp+6]
  129.       mov   cx,ax                         ; copy y to cx reg.
  130.       shl   ax,1                          ; 
  131.       shl   ax,1                          ; y = y * 4
  132.       add   cx,ax                         ; y = (y*4 + y) = 5*y
  133. dot_buffer_start:
  134.       add   cx,0a000h                     ; a0 -> ch = base page for ega
  135.       mov   ax,[bp+4]
  136.       and   al,07h                        ; al >= 0 and <= 7
  137.       mov   bx,offset pixel_table_        ; use al as lookup for bit position
  138.       xlat  pixel_table_                  ; al now contains bit to write
  139.       shr   si,1
  140.       shr   si,1
  141.       shr   si,1                          ; si = si / 8
  142.       mov   es,cx                         ; es now = base adr. + y * 5 * 16
  143.       or    es:[si],al
  144. #
  145.    }
  146.  
  147.  
  148. /***************************** L I N E _ D R A W ***********************/
  149. /*  This is the ultra fast line drawing routine.  It writes only in    */
  150. /*  white and s/r mode must be turned off                              */
  151.  
  152. void line_draw(x1,y1,x2,y2)
  153.    unsigned x1,y1,x2,y2;
  154.    {
  155. #asm
  156.       push  ds                         ; save ds reg.
  157.       mov   si,[bp+04h]                ; reg. si = x1
  158.       mov   di,[bp+08h]                ; reg. di = x2
  159.       mov   cx,[bp+06h]                ; reg. cx = y1
  160.       mov   dx,[bp+0ah]                ; reg. dx = y2
  161.       cmp   si,di                      ; cmp x1, x2
  162.       jle   swapxy                     ; skip if (x1<=x2)
  163.       xchg  cx,dx                      ; x1 > x2 so swap y1,y2
  164.       xchg  si,di                      ; and swap x1,x2
  165. swapxy:
  166.       sub   dx,cx                      ; dy = y2-y1
  167.       mov   al,80                      ; deldy = 80
  168.       jge   ydown                      ; skip if y1<=y2
  169.       neg   dx                         ; |y2-y1|
  170.       neg   al                         ; -80
  171. ydown:
  172.       sub   di,si                      ; absdx = x2-x1
  173.       cmp   di,dx                      ; di = absdx, dx = absdy
  174.       lahf                             ; save flags
  175.       jnl   minmax                     ; skip if absdx >= absdy
  176.       xchg  di,dx                      
  177. minmax:
  178.       xchg  ax,bp
  179. ; compute initial ds address (a000h + y * 80)
  180. ; al = initial pixel
  181.       mov   ax,cx                      ; copy y to ax reg.
  182.       shl   ax,1
  183.       shl   ax,1                       ; y = y * 4
  184.       add   cx,ax                      ; y = y * 4 + y = 5y
  185.       shl   cx,1
  186.       shl   cx,1
  187.       shl   cx,1
  188.       shl   cx,1                       ; y = 5y * 16
  189.       mov   bx,offset pixel_table_     ; get location of pixel lookup table
  190.       mov   al,07h
  191.       and   ax,si                      ; mask out bits > 8 
  192.       xlat  pixel_table_               ; get starting pixel location
  193.       sal   dx,1                       ; dx = delse = dmin * 2
  194.       xchg  ax,dx                      ; ax = delse, dx = pixel location
  195.       xchg  ax,bp                      ; ax = flags(absdx,absdy), bp=delse
  196.       sahf                             ; cmp absdx,absdy
  197.       pushf                            ; save flags on stack
  198.       cbw                              ; ax = deldy 
  199.       mov   cs:delsy+2,ax              ; save deldy
  200.       mov   cs:deldy+2,ax
  201.       mov   cs:deldy2+2,ax
  202.      
  203.       xchg  ax,bp                      ; ax = dmin * 2 = delse
  204.       mov   cs:delse+2,ax              ; save delse
  205.       mov   cs:delse2+2,ax
  206.       sub   ax,di                      ; ax = dmin * 2 - dmax = d
  207.       mov   bp,ax                      ; bp = d = error for start
  208.       sub   ax,di                      ; ax = dmin * 2 - dmax * 2
  209.       mov   cs:delde+2,ax              ; save delde
  210.       mov   cs:delde2+2,ax
  211.       sar   si,1
  212.       sar   si,1
  213.       sar   si,1                       ; x = x / 8
  214.       add   si,cx
  215. line_buffer_start:
  216.       mov   cx,0a000h
  217.       mov   ds,cx
  218.       popf
  219.       mov   cx,di
  220.       jns   delsx2
  221.  
  222.       or    [si],dl
  223.       or    cx,cx
  224.       jz    lineexit
  225.       or    bp,bp
  226.       jge   diagonal
  227.  
  228. straight:
  229. delsy:
  230.       add   si,1000h                   ; increment y by -80 or 80
  231.       or    [si],dl                    ; or in byte on screen
  232.       dec   cx                         ; decrement loop count
  233.       jz    lineexit                   ; jump to end if cx = 0
  234. delse:
  235.       add   bp,1000h                   ; add error term
  236.       js    straight
  237.  
  238. diagonal:
  239.       ror   dl,1                       ; rotate pixel right
  240.       jnc   noincr                     ; skip if dl > 0
  241.       inc   si                         ; increment x 
  242. noincr:
  243. deldy:
  244.       add   si,1000h
  245.       or    [si],dl                    ; write the dot
  246.       dec   cx                         ; decrement loop count
  247.       jz    lineexit
  248. delde:
  249.       add   bp,1000h                   ; add error term
  250.       js    straight                   ; if bp<0 goto straight
  251.       jmp   diagonal                   ; if bp>=0 goto diagonal
  252. ;
  253. ; absdeltax > absdeltay
  254. ;
  255. delsx2:
  256.       or    [si],dl
  257.       jcxz  lineexit
  258.       or    bp,bp
  259.       jge   diagonal2
  260. straight2:
  261.       ror   dl,1                       ; rotate pixel right
  262.       jnc   noincr2
  263.       inc   si
  264. noincr2:
  265.       or    [si],dl                    ; write the dot
  266.       dec   cx
  267.       jz    lineexit
  268. delse2:
  269.       add   bp,1000h
  270.       js    straight2
  271. diagonal2:
  272.       ror   dl,1
  273.       jnc   noincr3
  274.       inc   si
  275. noincr3:
  276. deldy2:
  277.       add   si,1000h
  278.       or    [si],dl
  279.       dec   cx
  280.       jz    lineexit
  281. delde2:
  282.       add   bp,1000h
  283.       js    straight2
  284.       jmp   diagonal2
  285. lineexit:
  286.       pop   ds
  287.       
  288. #      
  289.  
  290. }
  291.  
  292. /************************** C _ W R I T E _ D O T *************************/
  293. /* This is the fast version of the color write dot routine.               */
  294.  
  295. void c_write_dot(x,y)
  296.    unsigned x,y;
  297.    {
  298. #asm
  299.       mov   si,[bp+6]                     ; get y value off stack
  300.       mov   cx,si                         ; copy y to cx reg.
  301.       shl   si,1                          ; 
  302.       shl   si,1                          ; y = y * 4
  303.       add   cx,si                         ; y = (y*4 + y) = 5*y
  304. c_dot_buffer_start:
  305.       add   cx,0a000h                     ; a0 -> ch = base page for ega
  306.       mov   si,[bp+4]                     ; get x value off stack
  307.       mov   dx,03ceh                      ; select bit mask reg. for out
  308.       mov   al,08h                        ; to 03cfh.8
  309.       out   dx,al
  310.       mov   ax,si                         ; copy x to ax reg.
  311.       and   al,07h                        ; al >= 0 and <= 7
  312.       mov   bx,offset pixel_table_        ; use al as lookup for bit position
  313.       xlat  pixel_table_                  ; al now contains bit to write
  314.       shr   si,1
  315.       shr   si,1
  316.       shr   si,1                          ; si = si / 8
  317.       mov   es,cx                         ; es now = base adr. + y * 5 * 16
  318.       inc   dx                            ; mask all but desired pixel
  319.       out   dx,al                         ; output mask to 03fh.8
  320. ;
  321.       mov   al,es:[si]                    ; dummy read
  322.       mov   al,0ffh
  323.       mov   es:[si],al                    ; blank pixel
  324. ;
  325. #
  326.    }
  327.  
  328. /*************************** S H O W _ B U F F E R *************************/
  329. /*
  330.          function show_buffer(x)
  331.  
  332.                Input: x - (0 or 1) Note: this function is provided for double
  333.                                          buffering in 640x350 16 color mode.
  334.                                          You must have 256k in the EGA's
  335.                                          memory for this to work!!!!
  336.                Returns: none
  337. */
  338.  
  339. void show_buffer(x)
  340.    unsigned x;
  341.    {
  342. #asm
  343.       mov   ax,[bp+4]
  344.       mov   cx,03d4h
  345.       mov   dx,cx                           ; reg cx = 03d4h
  346.       or    ax,ax
  347.       jz    buffer0                         ; Jump if buffer 0 selected
  348.       mov   al,0ch                          ; Start Address High Register
  349.       out   dx,al                           ; Out 3d4,0c
  350.       inc   dx                              
  351.       mov   al,80h
  352.       out   dx,al                           ; Out 3d5,80
  353.       mov   dx,cx                           ; Now fix Address Low Register
  354.       mov   al,0dh
  355.       out   dx,al                           ; Out 3d4,0d
  356.       inc   dx
  357.       mov   al,00h
  358.       out   dx,al                           ; Out 3d5,00 
  359.       jmp   exo
  360. buffer0:         
  361.       mov   al,0ch                          ; Start Address High Register
  362.       out   dx,al                           ; Out 3d4,0c
  363.       inc   dx                              
  364.       xor   al,al
  365.       out   dx,al                           ; Out 3d5,00
  366.       mov   dx,cx                           ; Now fix Address Low Register
  367.       mov   al,0dh
  368.       out   dx,al                           ; Out 3d4,0d
  369.       inc   dx
  370.       xor   al,al
  371.       out   dx,al                           ; Out 3d5,00 
  372. exo:
  373. #
  374.  
  375.  
  376. /****************************** S E T _ C O L O R *************************/
  377. /*
  378.          function set_color(color)
  379.  
  380.             Input: color (0..15) = color Note: this routine must be used
  381.                                                before calling either 
  382.                                                color_write_line or 
  383.                                                color_write_dot. 
  384.             Returns: none
  385. */
  386.  
  387. void set_color(color)
  388.    unsigned color;
  389.    {
  390. #asm
  391.       mov   dx,03ceh                   ; Select s/r register
  392.       xor   al,al
  393.       out   dx,al
  394.       inc   dx
  395.       mov   al,[bp+04]                ; output color to s/r resister
  396.       out   dx,al
  397.       dec   dx                         ; dx = 03ce
  398.       mov   al,01                      ; Select s/r register enable
  399.       out   dx,al
  400.       inc   dx
  401.       mov   al,0ffh                    ; select s/r for all planes
  402.       out   dx,al
  403. #
  404.    }
  405.  
  406. /**************************** C L E A R _ C O L O R ***********************/
  407. /* 
  408.          function clear_color()
  409.  
  410.             Input: none
  411.  
  412.             Returns: none       Note:  the function must be called
  413.                                        after using set_color. Otherwise
  414.                                        you will get garbage on the
  415.                                        screen when attempting to write
  416.                                        text with bios.
  417. */
  418.  
  419. void clear_color()
  420.    {
  421. #asm
  422.       mov   dx,03ceh
  423.       mov   al,01                      ; Out 03ce,01
  424.       out   dx,al
  425.       inc   dx                         
  426.       dec   al                         ; Disable s/r on all planes
  427.       out   dx,al                      ; Out 03cf,00
  428.       dec   dx
  429.       mov   al,08                      ; Select bit mask register
  430.       out   dx,al                      ; Out 03ce,08
  431.       inc   dx
  432.       mov   al,0ffh                    ; Turn bit mask off
  433.       out   dx,al                      ; Out 03cf,ff
  434. #
  435. }
  436.  
  437. /************************ C _ L I N E _ D R A W ****************************/      
  438. /* this is the color fast line draw */
  439. void c_line_draw(x1,y1,x2,y2)
  440.    unsigned x1,y1,x2,y2;
  441.    {
  442. #asm
  443.       push  ds                         ; save ds reg.
  444.       mov   si,[bp+04h]                ; reg. si = x1
  445.       mov   di,[bp+08h]                ; reg. di = x2
  446.       mov   cx,[bp+06h]                ; reg. cx = y1
  447.       mov   dx,[bp+0ah]                ; reg. dx = y2
  448.       cmp   si,di                      ; cmp x1, x2
  449.       jle   swapxyc                    ; skip if (x1<=x2)
  450.       xchg  cx,dx                      ; x1 > x2 so swap y1,y2
  451.       xchg  si,di                      ; and swap x1,x2
  452. swapxyc:
  453.       sub   dx,cx                      ; dy = y2-y1
  454.       mov   al,80                      ; deldy = 80
  455.       jge   ydownc                     ; skip if y1<=y2
  456.       neg   dx                         ; |y2-y1|
  457.       neg   al                         ; -80
  458. ydownc:
  459.       sub   di,si                      ; absdx = x2-x1
  460.       cmp   di,dx                      ; di = absdx, dx = absdy
  461.       lahf                             ; save flags
  462.       jnl   minmaxc                    ; skip if absdx >= absdy
  463.       xchg  di,dx                      
  464. minmaxc:
  465.       xchg  ax,bp
  466. ; compute initial ds address (a000h + y * 80)
  467. ; al = initial pixel
  468.       mov   ax,cx                      ; copy y to ax reg.
  469.       shl   ax,1
  470.       shl   ax,1                       ; y = y * 4
  471.       add   cx,ax                      ; y = y * 4 + y = 5y
  472.       shl   cx,1
  473.       shl   cx,1
  474.       shl   cx,1
  475.       shl   cx,1                       ; y = 5y * 16
  476.       mov   bx,offset pixel_table_     ; get location of pixel lookup table
  477.       mov   al,07h
  478.       and   ax,si                      ; mask out bits > 8 
  479.       xlat  pixel_table_               ; get starting pixel location
  480.       sal   dx,1                       ; dx = delse = dmin * 2
  481.       xchg  ax,dx                      ; ax = delse, dx = pixel location
  482.       xchg  ax,bp                      ; ax = flags(absdx,absdy), bp=delse
  483.       sahf                             ; cmp absdx,absdy
  484.       pushf                            ; save flags on stack
  485.       cbw                              ; ax = deldy 
  486.       mov   cs:delsyc+2,ax             ; save deldy
  487.       mov   cs:deldyc+2,ax
  488.       mov   cs:deldy2c+2,ax
  489.      
  490.       xchg  ax,bp                      ; ax = dmin * 2 = delse
  491.       mov   cs:delsec+2,ax              ; save delse
  492.       mov   cs:delse2c+2,ax
  493.       sub   ax,di                      ; ax = dmin * 2 - dmax = d
  494.       mov   bp,ax                      ; bp = d = error for start
  495.       sub   ax,di                      ; ax = dmin * 2 - dmax * 2
  496.       mov   cs:deldec+2,ax              ; save delde
  497.       mov   cs:delde2c+2,ax
  498.       sar   si,1
  499.       sar   si,1
  500.       sar   si,1                       ; x = x / 8
  501.       add   si,cx
  502. c_line_buffer_start:
  503.       mov   cx,0a000h
  504.       mov   ds,cx
  505.       mov   cx,di
  506.       mov   ah,dl
  507.       mov   al,08                      ; select bit mask register
  508.       mov   dx,03ceh
  509.       out   dx,al   
  510.       inc   dx
  511.       mov   al,ah
  512.       out   dx,al                      ; output bit to mask register
  513.       dec   dx
  514.       mov   al,[si]                    ; dummy read
  515.       mov   al,0ffh
  516.       mov   [si],al                    ; write all ones to address
  517.       or    cx,cx                      ; check for zero line length
  518.       jz    lineexitc
  519.       popf
  520.       jns   delsx2c
  521.       or    bp,bp
  522.       jge   diagonalc
  523. straightc:
  524. delsyc:
  525.       add   si,1000h                   ; increment y by -80 or 80
  526.       mov   al,[si]                    ; dummy read for data latches on ega
  527.       mov   al,0ffh
  528.       mov   [si],al                    ; write all ones to address <- si
  529.       dec   cx                         ; decrement loop count
  530.       jz    lineexitc                  ; jump to end if cx = 0
  531. delsec:
  532.       add   bp,1000h                   ; add error term
  533.       js    straightc
  534. diagonalc:
  535.       ror   ah,1                       ; rotate pixel right
  536.       jnc   noincrc                    ; skip if ah > 0
  537.       inc   si                         ; increment x 
  538. noincrc:
  539.       mov   al,08                      ; store bit in bit mask reg.
  540.       out   dx,al
  541.       mov   al,ah
  542.       inc   dx
  543.       out   dx,al
  544.       dec    dx    
  545. deldyc:
  546.       add   si,1000h
  547.       mov   al,[si]                    ; dummy read
  548.       mov   al,0ffh
  549.       mov   [si],al                    ; write all ones
  550.       dec   cx                         ; decrement loop count
  551.       jz    lineexitc
  552. deldec:
  553.       add   bp,1000h                   ; add error term
  554.       js    straightc                  ; if bp<0 goto straight
  555.       jmp   diagonalc                  ; if bp>=0 goto diagonal
  556. ;
  557. ; absdeltax > absdeltay
  558. ;
  559. delsx2c:
  560.       or    bp,bp
  561.       jge   diagonal2c
  562. straight2c:
  563.       ror   ah,1                       ; rotate pixel right
  564.       jnc   noincr2c
  565.       inc   si
  566. noincr2c:
  567.       mov   al,08                      ; store bit in bit mask reg.
  568.       out   dx,al
  569.       mov   al,ah
  570.       inc   dx
  571.       out   dx,al
  572.       dec   dx
  573.       mov   al,[si]                    ; dummy read
  574.       mov   al,0ffh
  575.       mov   [si],al                    ; write all ones
  576.       dec   cx
  577.       jz    lineexitc
  578. delse2c:
  579.       add   bp,1000h
  580.       js    straight2c
  581. diagonal2c:
  582.       ror   ah,1
  583.       jnc   noincr3c
  584.       inc   si
  585. noincr3c:
  586.       mov   al,08                      ; store bit in bit mask reg.
  587.       out   dx,al
  588.       mov   al,ah
  589.       inc   dx
  590.       out   dx,al
  591.       dec    dx
  592. deldy2c:
  593.       add   si,1000h                   ; y increment or decrement by 80
  594.       mov   al,[si]                    ; dummy read
  595.       mov   al,0ffh
  596.       mov   [si],ah
  597.       dec   cx
  598.       jz    lineexitc
  599. delde2c:
  600.       add   bp,1000h
  601.       js    straight2c
  602.       jmp   diagonal2c
  603. lineexitc:
  604.       pop   ds                         ; restore data segment
  605. #
  606. }
  607.  
  608. /********************** S E T _ W R I T E _ B U F F E R ********************/
  609. /*
  610.          function set_write_buffer(x)
  611.  
  612.                Input: x - (0 or 1) Note: this function is provided for double
  613.                                          buffering in 640x350 16 color mode.
  614.                                          You must have 256k in the EGA's
  615.                                          memory for this to work!!!!
  616.                Returns: none
  617. */
  618.  
  619. void set_write_buffer(x)
  620.    unsigned x;
  621.    {
  622. #asm
  623.       mov   ax,[bp+4]
  624.       or    ax,ax
  625.       mov   ax,0a000h
  626.       jz    lower_write
  627.       mov   ax,0a800h
  628. lower_write:
  629.       mov   cs:dot_buffer_start+2,ax
  630.       mov   cs:line_buffer_start+1,ax
  631.       mov   cs:c_line_buffer_start+1,ax
  632.       mov   cs:c_dot_buffer_start+2,ax
  633. #
  634.  
  635. void  write_lower_pattern()
  636.   {
  637.       unsigned int i,j,k=0;
  638.       set_color(3);                  /* Set the color to cyan */
  639.       for(i=150;i<340;i += 3)        /* Draw pattern with cyan lines */
  640.          c_line_draw(1,150,600,i);
  641.  
  642.       set_color(4);                     /* Set the color to red  */
  643.       for(i=1;i<340;i += 3)          /* Draw pattern with red lines */
  644.          c_line_draw(300,1,100,i);
  645.  
  646.       set_color(1);                  /* Set the color to blue  */
  647.  
  648.       for(i=0;i<=340;i += 10)        /* Draw a grid pattern    */
  649.          c_line_draw(1,i,600,i);
  650.       for(i=0;i<=600;i += 10)
  651.          c_line_draw(i,1,i,340);
  652.  
  653.       for(i=300;i<600;i += 4,k++)    /* Show off the color dot writing */
  654.       {
  655.        set_color(k);  
  656.        for(j=1;j<150;++j)
  657.         {
  658.           c_write_dot(i,j);
  659.         }
  660.       }
  661.   }
  662.  
  663.  
  664. void  write_upper_pattern()
  665.   {
  666.       unsigned int i,j,k=0;
  667.       set_color(5);                  /* Set the color to magenta */
  668.       for(i=150;i<340;i += 4)        /* Draw pattern with magenta lines */
  669.          c_line_draw(4,150,600,i);
  670.  
  671.       set_color(2);                        /* Set the color to green  */
  672.       for(i=1;i<340;i += 2)          /* Draw pattern with red lines */
  673.          c_line_draw(300,1,200,i);
  674.  
  675.       set_color(12);                  /* Set the color to bright red  */
  676.  
  677.       for(i=0;i<=340;i += 20)         /* Draw a grid pattern    */
  678.          c_line_draw(1,i,600,i);
  679.       for(i=0;i<=600;i += 20)
  680.          c_line_draw(i,1,i,340);
  681.  
  682.       for(i=300;i<600;i += 5,k++)    /* Show off the color dot writing */
  683.       {
  684.        set_color(k);  
  685.        for(j=150;j<300;++j)
  686.         {
  687.           c_write_dot(i,j);
  688.         }
  689.       }
  690.   }
  691.  
  692. void draw_box(size)
  693.    unsigned int size;
  694.    {
  695.       c_line_draw(0,0,size,0);
  696.       c_line_draw(size,0,size,size);
  697.       c_line_draw(size,size,0,size);
  698.       c_line_draw(0,size,0,0);
  699.    }   
  700.  
  701. /* Here is a little example to show you how to use the above functions ! */
  702.  
  703. main()
  704.    {
  705.       unsigned int i,h,times, delay;
  706.       set_video_mode(0x10);    /* SET THE HIRES (640X350 - 16 COLOR) */
  707.       set_write_buffer(0);     /* Do all writing to lower buffer */
  708.       show_buffer(0);          /* Display lower buffer */
  709.       write_lower_pattern();   /* Write 'stuff' to lower buffer */
  710.  
  711.       set_write_buffer(1);     /* Do all writing to upper buffer */
  712.       write_upper_pattern();   /* Write 'stuff' to upper buffer */
  713.       show_buffer(1);          /* Display the upper buffer */
  714.       for(times=0;times<50000;times++);
  715.       show_buffer(0);
  716.       for(times=0;times<2;times++)
  717.        {
  718.          show_buffer(0);
  719.          for(delay=0;delay<40000;++delay);
  720.          show_buffer(1);
  721.          for(delay=0;delay<40000;++delay);
  722.        }
  723.       set_video_mode(0x10);
  724.       show_buffer(0);
  725.       set_write_buffer(0);
  726.  
  727.       for(h=0;h<20;++h)
  728.        for(i=1;i<16;++i)
  729.         {
  730.          set_color((i+h) & 15);
  731.          if(i % 2)
  732.           {
  733.             show_buffer(0);
  734.             set_write_buffer(1);
  735.           }
  736.          else
  737.           {
  738.             show_buffer(1);
  739.             set_write_buffer(0);
  740.           } 
  741.          for(times=i*20-10;times<i*20;times++)
  742.              draw_box(times);
  743.          }
  744.  
  745.       show_buffer(0);
  746.  
  747.       clear_color();                 /* You need this command to     */
  748.                                      /* clean up after your graphics */
  749.                                      /* operations                   */ 
  750.       printf("All done......\n\n");
  751.    }
  752.